<template>
    <div>
        <el-table
            :data="
                lessorsData.filter(
                    (data) =>
                        !search ||
                        data.account
                            .toLowerCase()
                            .includes(search.toLowerCase())
                )
            "
            style="width: 100%"
            :fit="true"
        >
            <el-table-column type="index" label="编号" width="300px">
            </el-table-column>
            <el-table-column label="账号" prop="account"> </el-table-column>
            <el-table-column label="联系方式" prop="phone"> </el-table-column>
            <el-table-column label="信用" prop="credits"> </el-table-column>
            <el-table-column label="冻结">
                <template slot-scope="scope">
                    <el-switch
                        v-model="scope.row.state"
                        active-text="冻结"
                        inactive-text="解冻"
                        active-value="2"
                        inactive-value="1"
                        @change="
                            frozenLessorAndCreateLogs({
                                _id: scope.row._id,
                                state: scope.row.state,
                                account:scope.row.account
                            })
                        "
                    >
                    </el-switch>
                </template>
            </el-table-column>
            <el-table-column align="right">
                <template slot="header" slot-scope="scope">
                    <el-input
                        v-model="search"
                        size="mini"
                        placeholder="请输入账号关键字"
                    />
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="getData.currentpage"
      :page-sizes="[5, 7, 10, 15]"
      :page-size="getData.pagesize-0"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total-0">
    </el-pagination>
    </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
import axios from '../../http/axios.js'
const { mapState, mapActions, mapMutations } = createNamespacedHelpers(
    "lessors"
);
export default {
    props:['token'],
    data() {
        return {
            search: "",
            updatePasswordId: "",
            adminState: "",
            newLessors: {
                account: "",
                password: "",
            },
            getData:{
            currentpage:1,
            pagesize:5
        }
        };
    },
    mounted() {
        this.getLessors(this.getData);
        
    },
    computed: {
        ...mapState(["lessorsData",'total']),
        
    },
    methods: {
        handleSizeChange(val) {
        this.getData.pagesize=val
        console.log(this.getData);
        this.getLessors(this.getData);
      },
      handleCurrentChange(val) {
        this.getData.currentpage=val
        this.getLessors(this.getData);
      },
        ...mapActions([
            "getLessors",
            "frozenLessors",
        ]),
         frozenLessorAndCreateLogs(data){
            this.frozenLessors(data)
             console.log(data);
            if(data.state==1){
                 axios({
                    url:'/logs/createLogs',
                    method:'post',
                    data:{
                        name:this.token,
                        operation:'解冻出租人'+data.account,
                        result:'成功'
                    }
                    })
            }else{
                 axios({
                    url:'/logs/createLogs',
                    method:'post',
                    data:{
                        name:this.token,
                        operation:'冻结出租人'+data.account,
                        result:'成功'
                    }
                    })
            }
        },
    },
};
</script>